package com.xx.springboot.improve.web;

import com.xx.springboot.improve.domain.User;
import com.xx.springboot.improve.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.constraints.NotNull;

/**
 * author: XiongXin
 * description:
 * time: 2017/3/8.
 */
@Controller
@RequestMapping("users")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    @ResponseBody
    public User getUser(@NotNull(message = "id不能为空")@PathVariable("id") String id){
        return userService.getUserById(id);
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    @ResponseBody
    public Page<User> getUsers(User user, Pageable pageable){
        return userService.findAllUsersByPage(user, pageable);
    }

    @RequestMapping(value = "page", method = RequestMethod.GET)
    public String toUserPage(){
        return "user";
    }

}
